import { createApp } from 'vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import 'element-plus/theme-chalk/dark/css-vars.css'
import App from './App.vue'
import { Details, DetailsWin, Folder, PwdmApi, Tools } from './assets/core'
import { defineStore, createPinia } from 'pinia'

let isDark = false;
let nowHour = Tools.dateFtt("HH", new Date());
if (Number(nowHour) >= 18 || Number(nowHour) < 7) {
    document.getElementsByTagName('html')[0].className = "dark";
    isDark = true;
}

interface StoreStataType {
    pwdmApi: PwdmApi;
    selectMenuIndex: string;
    folderList: Folder[];
    refreshItem: boolean;
    selectDetails: Details;
    detailsWin: DetailsWin;
    dark: boolean;
}

export const useStore = defineStore('main', {
    state: (): StoreStataType => {
        return {
            pwdmApi: new PwdmApi(),
            selectMenuIndex: "2",//选中的菜单id，2：所有项目
            folderList: [],
            refreshItem: false,//是否刷新item列表
            selectDetails: {},
            detailsWin: 0, //0:没有任何窗口；1:详情窗口；2:编辑窗口
            dark: isDark
        }
    },
    getters: {
        /**
         * 格式化显示最后修改时间
         * @param state 
         */
        lastModifyDate(state) {
            if (state.selectDetails.updateTime) {
                return Tools.dateFtt('yyyy-MM-dd HH:mm:ss', new Date(state.selectDetails.updateTime));
            }
            return "";
        }
    }
});

const app = createApp(App);
app.use(createPinia());
app.use(ElementPlus);
app.mount('#app');

console.log("Element Plus版本：" + ElementPlus.version);
console.log("Vue版本：" + app.version);